#!/usr/bin/env python
import logging
from binance.um_futures import UMFutures
from binance.lib.utils import config_logging
from binance.error import ClientError

config_logging(logging, logging.INFO)

#只能获取账户信息的 apikey
key = "lSfS73A8jxifi2btCmE7fPnhrg5Zf333pyGZkuuwHvZ7GrZg11gyE52SrfY0Kmms"
secret = "8CUn0fvnmJ7ufDZ0BuVuMzu2jOkOb9vfQ077p3iQTyL6IL6WquQa3AgQ8BIW1cAS"
# hmac_client = UMFutures(key='P82r2pxV0g9SzjmvVMDjyTQMBjpdoFHTxlXarFLVODdfp12KXMPbHqToaVlxu7o5', secret='zt6IPo05G09Ml89EAsVR7P1LzQsnO5l9PRkxZO4Os389dBd9lfWh6NWw2ph9YQeM')
hmac_client = UMFutures(key='3S4j9rBxss0KBivifkgMMEykgWad9GEMl9hdgMhViiwKGNDy5NoLkYHIDg6K3VU5', secret='NzWj2BnVToddcO39tkJp7N1Xz041EYwzgVibMV7czf0ZaHWfuCM8GHnO8pBp03xH')

# logging.info(hmac_client.account(recvWindow=6000))


try:

    params = {
        'symbol': 'QUICKUSDT',
        'side': 'BUY',
        'type': 'MARKET',
        'quantity': 15108,  # 这里需要根据币安的精度要求进行调整
    }
    # order = hmac_client.cancel_order(symbol='QUICKUSDT',orderId='17032222')
    # order = hmac_client.new_order(**params, recvWindow=30000)

    # logging.info(order)
    response = hmac_client.account(recvWindow=60000)
    logging.info(response['totalMarginBalance'])
    for position in response['positions']:
        symbol = position['symbol']
        # if symbol == 'TLMUSDT' or symbol == 'ARPAUSDT':
        #     print(position)

        if abs(float(position['positionAmt'])) > 0: #== 'REEFUSDT' or position['symbol'] == 'LOOMUSDT':
            print(position)
    # logging.info(response)
except ClientError as error:
    logging.error(
        "Found error. status: {}, error code: {}, error message: {}".format(
            error.status_code, error.error_code, error.error_message
        )
    )